When an error occurs, an Error object is generated and several properties are filled in. Heres a list of some of the Error objects properties that are filled in:
The Description property is filled in with a description of the error thats returned from the provider.
The NativeError property contains the error number reported from the data source itself. This number can be different for every database system.
The Number property is a unique number that identifies the error. This number is ADO specific and will not change between database systems.
The Source property contains the name of the service provider, the name of the table, the SQL statement, or the name of the object that generated the error.
The SQLState property is a five-character string that conforms to the ANSI SQL standards and is generally reported back from the underlying ODBC driver or OLE DB provider.
Error Reporting
Heres a simple example of an error handler you can call from any function that uses ADO. You should always pass in the Connection object to this procedure because you cant rely on having just one connection. For example, if you open a Recordset object with a connection string, you need to pass in the ActiveConnection property to the ErrorHandler() procedure.
Call ErrorHandler(oRS.ActiveConnection)
However, if youre using a global Connection object, you need to pass that object to the ErrorHandler() procedure.
Call ErrorHandler(goConn)
Examples Filenames: Error.frm and ADO.bas
Public Sub ErrorHandler(oConn As Connection)
Dim oErr As Error
Dim strMsg As String